import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTCreationException;
import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT;

public class AA {
	public static void main(String[] args) {
		String token = null;
		try {
		    Algorithm algorithm = Algorithm.HMAC256("upliftserv");
		    token = JWT.create()
		        .withIssuer("auth0").withClaim("userId", "张三")
		        .sign(algorithm);
		    
		    System.out.println(token);

		} catch (JWTCreationException exception){
		    //Invalid Signing configuration / Couldn't convert Claims.
		}
		
		try {
			Algorithm algorithm = Algorithm.HMAC256("upliftserv");
			JWTVerifier jwtVerifier = JWT.require(algorithm).build();
			DecodedJWT decodedJWT = jwtVerifier.verify(token);
			
			Claim claim = decodedJWT.getClaim("userId");
			
			String userId = claim.asString();
			
			System.out.println(userId + decodedJWT.getExpiresAt());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
